EMMA Coverage Report (generated Thu Sep 01 16:40:51 CEST 2016)
[all classes][kdk.android.simplydo]

COVERAGE SUMMARY FOR SOURCE FILE [ItemListSorter.java]

nameclass, %method, %block, %line, %
ItemListSorter.java100% (4/4)100% (13/13)88%  (197/224)92%  (45/49)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ItemListSorter100% (1/1)100% (7/7)80%  (105/132)89%  (34/38)
sort (List): void 100% (1/1)64%  (23/36)82%  (9/11)
setSortingMode (String): void 100% (1/1)64%  (25/39)78%  (7/9)
ItemListSorter (): void 100% (1/1)100% (21/21)100% (5/5)
markActivityUpdate (ItemDesc): void 100% (1/1)100% (7/7)100% (3/3)
markAsSorted (List): void 100% (1/1)100% (15/15)100% (4/4)
markEditUpdate (ItemDesc): void 100% (1/1)100% (7/7)100% (3/3)
markStarredUpdate (ItemDesc): void 100% (1/1)100% (7/7)100% (3/3)
     
class ItemListSorter$1100% (1/1)100% (2/2)100% (12/12)100% (2/2)
ItemListSorter$1 (ItemListSorter): void 100% (1/1)100% (6/6)100% (1/1)
compare (ItemDesc, ItemDesc): int 100% (1/1)100% (6/6)100% (1/1)
     
class ItemListSorter$2100% (1/1)100% (2/2)100% (33/33)100% (6/6)
ItemListSorter$2 (ItemListSorter): void 100% (1/1)100% (6/6)100% (1/1)
compare (ItemDesc, ItemDesc): int 100% (1/1)100% (27/27)100% (5/5)
     
class ItemListSorter$3100% (1/1)100% (2/2)100% (47/47)100% (6/6)
ItemListSorter$3 (ItemListSorter): void 100% (1/1)100% (6/6)100% (1/1)
compare (ItemDesc, ItemDesc): int 100% (1/1)100% (41/41)100% (5/5)

1/*
2 * Copyright (C) 2010 Keith Kildare
3 * 
4 * This file is part of SimplyDo.
5 * 
6 * SimplyDo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * 
11 * SimplyDo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 * 
16 * You should have received a copy of the GNU General Public License
17 * along with SimplyDo.  If not, see <http://www.gnu.org/licenses/>.
18 * 
19 */
20package kdk.android.simplydo;
21 
22import java.util.Collections;
23import java.util.Comparator;
24import java.util.List;
25 
26import android.util.Log;
27 
28public class ItemListSorter
29{
30    public static final String PREF_NONE = "none";
31    public static final String PREF_STARRED = "starred";
32    public static final String PREF_ACTIVE_STARRED = "activityStarred";
33    
34    private static final int NONE = 0;
35    private static final int STARRED = 1;
36    private static final int ACTIVE_STARRED = 2;
37 
38    private int sortingMode;
39    
40    private Comparator<ItemDesc> idCompare;
41    private Comparator<ItemDesc> starredCompare;
42    private Comparator<ItemDesc> activeStarredCompare;
43 
44    
45    public ItemListSorter()
46    {
47        idCompare = new Comparator<ItemDesc>() {
48            @Override
49            public int compare(ItemDesc object1, ItemDesc object2)
50            {
51                return object2.getId() - object1.getId();
52            }
53        };
54        
55        starredCompare = new Comparator<ItemDesc>() {
56            @Override
57            public int compare(ItemDesc o1, ItemDesc o2)
58            {
59                int w1 = o1.isStar()?1:0;
60                int w2 = o2.isStar()?1:0;
61                if(w2 == w1)
62                {
63                    return o1.getLabel().compareToIgnoreCase(o2.getLabel());
64                }
65                else
66                {
67                    return w2 - w1;
68                }
69            }
70        };
71        
72        activeStarredCompare = new Comparator<ItemDesc>() {
73            @Override
74            public int compare(ItemDesc o1, ItemDesc o2)
75            {
76                int w1 = (o1.isStar()?1:0) + (o1.isActive()?0:-2);
77                int w2 = (o2.isStar()?1:0) + (o2.isActive()?0:-2);
78                if(w2 == w1)
79                {
80                    return o1.getLabel().compareToIgnoreCase(o2.getLabel());
81                }
82                else
83                {
84                    return w2 - w1;
85                }
86            }
87        };
88    }
89    
90    public void setSortingMode(String mode)
91    {
92        if(PREF_NONE.equals(mode))
93        {
94            sortingMode = NONE;
95        }
96        else if(PREF_STARRED.equals(mode))
97        {
98            sortingMode = STARRED;
99        }
100        else if(PREF_ACTIVE_STARRED.equals(mode))
101        {
102            sortingMode = ACTIVE_STARRED;
103        }
104        else
105        {
106            sortingMode = NONE;
107            Log.w(L.TAG, "Unknown item sorting mode " + mode);
108        }
109    }
110    
111    
112    public void markEditUpdate(ItemDesc item)
113    {
114        switch(sortingMode)
115        {
116        case ACTIVE_STARRED:
117        case STARRED:
118            item.setSorted(false);
119            break;
120        }        
121    }
122    
123    
124    public void markActivityUpdate(ItemDesc item)
125    {
126        switch(sortingMode)
127        {
128        case ACTIVE_STARRED:
129            item.setSorted(false);
130            break;
131        }        
132    }
133    
134    
135    public void markStarredUpdate(ItemDesc item)
136    {
137        switch(sortingMode)
138        {
139        case ACTIVE_STARRED:
140        case STARRED:
141            item.setSorted(false);
142            break;
143        }        
144    }
145    
146    
147    public void sort(List<ItemDesc> list)
148    {
149        if(list == null)
150        {
151            return;
152        }
153        
154        switch(sortingMode)
155        {
156        default:
157            Log.w(L.TAG, "Unknown item sorting enum " + sortingMode);
158            // fall through
159        case NONE:
160            // actually sorted by db id
161            Collections.sort(list, idCompare);
162            break;
163        case STARRED:
164            Collections.sort(list, starredCompare);
165            break;
166        case ACTIVE_STARRED:
167            Collections.sort(list, activeStarredCompare);
168            break;
169        }
170        
171        markAsSorted(list);
172    }
173 
174    private void markAsSorted(List<ItemDesc> items)
175    {
176        for(ItemDesc item : items)
177        {
178            item.setSorted(true);
179        }
180    }
181}

[all classes][kdk.android.simplydo]
EMMA 2.0.5312 (C) Vladimir Roubtsov